/*var data=[
				{id:"01",name:"重庆"},
				{id:"0101",name:"渝北区",parentId:"01"},
				{id:"0102",name:"南岸区",parentId:"01"},
				{id:"0103",name:"北碚区",parentId:"01"},
				{id:"02",name:"四川"},
				{id:"0201",name:"成都",parentId:"02"},
				{id:"020101",name:"武侯区",parentId:"0201"},
				{id:"0202",name:"绵阳",parentId:"nidaye"}
			];*/
			
var  listree=function (list) {
				//保存所有根节点
				var roots=[];
				//保存所有节点
				var nodeMap={};
				list.filter(function(node){
					node.key=node.id;
					node.title=node.name;				
					nodeMap[node.id]=node;
					//如果父节点id未定义或未null,则表示未跟节点
					if(node.parentId===null||typeof node.parentId==="undefined"){
						roots.push(node);
						return false;
					}
					return true;
				}).forEach(function(node){
					//找到父节点
					var parent=nodeMap[node.parentId];
					if(parent){
						(parent.children=parent.children||[]).push(node);
					}else{
						//未找到父节点
						console.error("节点"+node+"未找到父节点");
					}
				});
				return roots;
			};